import { Keywords } from "../flows/Keywords";
import { Command } from "./Command";
import MessageStore from "../service/MessageStore";

export class Add extends Command {
    messageNumber = 5;

    async execute(): Promise<string> {
        if(!this.isValid(Keywords.ADD)) return '[ADD] Not valid command.';
        const tail: string = this.getTail();
        
        if(tail === '/') return MessageStore.getPreviousValue();

        if(this.isValidMessageNumber(tail))
            return MessageStore.getPreviousValue(tail as unknown as number);

        return '[ADD] Index out of range';
        // return await this.storage.downloadFromBuffer(tail);
    }

    private isValidMessageNumber(tail: string): boolean {
        let flag: boolean = false;
        for(let i=0; i<this.messageNumber; i++){
            if(tail === i.toString())
                flag = true;
        }
        return flag;
    }
}